﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;
using System.Web;

namespace POSSystem.BLL
{
    public class View_Customers : _View_Customers
    {
        public static View_Customers GetAllActiveViewCustomers()
        {
            try
            {
                View_Customers view_customersTb = new View_Customers();
                view_customersTb.Where.Deleted.Value = false;
                view_customersTb.Query.Load();
                return view_customersTb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_Customers.cs", "GetAllActiveViewCustomers", ex.StackTrace);
                throw new Exception("View_Customers.GetAllActiveViewCustomers(): " + ex.Message);
            }
        }

        public static View_Customers GetCustomerByID(int id)
        {
            try
            {
                View_Customers view_customersTb = new View_Customers();
                view_customersTb.Where.ID.Value = id;
                view_customersTb.Query.Load();
                return view_customersTb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_Customers.cs", "GetCustomerByID", ex.StackTrace);
                throw new Exception("View_Customers.GetCustomerByID(): " + ex.Message);
            }
        }

        public static View_Customers GetCustomerByEmail(string email)
        {
            try
            {
                View_Customers view_customersTb = new View_Customers();
                view_customersTb.Where.Email.Value = email;
                view_customersTb.Where.Deleted.Value = false;
                view_customersTb.Query.Load();
                return view_customersTb;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_Customers.cs", "GetCustomerByEmail", ex.StackTrace);
                throw new Exception("View_Customers.GetCustomerByEmail(): " + ex.Message);
            }
        }

        public static bool GetPriceType(int id)
        {
            try
            {
                View_Customers view_customersTb = new View_Customers();
                view_customersTb.Query.AddResultColumn(View_Customers.ColumnNames.DealerPrice);
                view_customersTb.Where.ID.Value = id;
                view_customersTb.Query.Load();
                if(view_customersTb.RowCount > 0)
                    return view_customersTb.DealerPrice;
                return false;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_Customers.cs", "GetPriceType", ex.StackTrace);
                throw new Exception("View_Customers.GetPriceType(): " + ex.Message);
            }
        }

        public static View_Customers GetCurrentUser()
        {
            return (View_Customers)HttpContext.Current.Session["SESSION_CUSTOMER"];
        }

        public static void SetCurrentUser(View_Customers cust)
        {
            HttpContext.Current.Session["SESSION_CUSTOMER"] = cust;
        }
    }
}
